Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

724
Views
Use @jest-environment jsdom y @jest-environment node ambos en el mismo proyecto [Jest-ReactJS]

Estamos usando "Jest with React Testing Library" para pruebas unitarias en nuestro proyecto. En el mismo proyecto tenemos algunos casos que necesitan "@jest-environment jsdom" y algunos casos necesitan el node @jest-environment. ¿Cómo podemos cambiar esto en un archivo de caso de prueba?

Tenemos debajo del archivo jest.config.js:

 /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
 module.exports = {
 preset: 'ts-jest',
 testEnvironment: 'node'
 };

Intenté el siguiente enfoque, pero no funcionó en mi experiencia.

 /**
 * @jest-environment jsdom
 */

test('use jsdom in this test file', () => {
 const element = document.createElement('div');
 expect(element).not.toBeNull();
});

/**
 * @jest-environment node
 */

test('do not use jsdom in this test file', () => {
 console.log(window); // this will fail as node doesn't have a window object
});
almost 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!